package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/images")
public class ImagesController {

    @Autowired
    private IUserService userService;

    @PostMapping
    public Map upload(MultipartFile file) {
        Map<String, Object> map = new HashMap<>();
        try {
            map.put("url", UploadUtil.uploadQiniu(file));
            //成功上传到服务器状态设为1
            map.put("status", 1);
        } catch (Exception e) {
            //失败则设为0
            map.put("status", 0);
            map.put("msg", e.getMessage());
            e.printStackTrace();
        }
        return map;
    }


}
